home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Atari Mega Archive 1
/
Atari Mega Archive - Volume 1.iso
/
language
/
pcl_src.zoo
/
defs.lsp
< prev
next >
Wrap
Lisp/Scheme
|
1992-09-09
|
28KB
|
823 lines
;;;-*-Mode:LISP; Package:(PCL LISP 1000); Base:10; Syntax:Common-lisp -*-
;;;
;;; *************************************************************************
;;; Copyright (c) 1985, 1986, 1987, 1988, 1989, 1990 Xerox Corporation.
;;; All rights reserved.
;;;
;;; Use and copying of this software and preparation of derivative works
;;; based upon this software are permitted. Any distribution of this
;;; software or derivative works must comply with all applicable United
;;; States export control laws.
;;;
;;; This software is made available AS IS, and Xerox Corporation makes no
;;; warranty about the software, its performance or its conformity to any
;;; specification.
;;;
;;; Any person obtaining a copy of this software is requested to send their
;;; name and post office or electronic mail address to:
;;; CommonLoops Coordinator
;;; Xerox PARC
;;; 3333 Coyote Hill Rd.
;;; Palo Alto, CA 94304
;;; (or send Arpanet mail to CommonLoops-Coordinator.pa@Xerox.arpa)
;;;
;;; Suggestions, comments and requests for improvements are also welcome.
;;; *************************************************************************
;;;
(in-package 'pcl)
(eval-when (compile load eval)
(defvar *defclass-times* '(load eval)) ;Probably have to change this
;if you use defconstructor.
(defvar *defmethod-times* '(load eval))
(defvar *defgeneric-times* '(load eval))
(defvar *boot-state* ()) ;NIL
;EARLY
;BRAID
;COMPLETE
)
(eval-when (load eval)
(when (eq *boot-state* 'complete)
(error "Trying to load (or compile) PCL in an environment in which it~%~
has already been loaded. This doesn't work, you will have to~%~
get a fresh lisp (reboot) and then load PCL."))
(when *boot-state*
(cerror "Try loading (or compiling) PCL anyways."
"Trying to load (or compile) PCL in an environment in which it~%~
has already been partially loaded. This may not work, you may~%~
need to get a fresh lisp (reboot) and then load PCL."))
)
;;;
;;; This is like fdefinition on the Lispm. If Common Lisp had something like
;;; function specs I wouldn't need this. On the other hand, I don't like the
;;; way this really works so maybe function specs aren't really right either?
;;;
;;; I also don't understand the real implications of a Lisp-1 on this sort of
;;; thing. Certainly some of the lossage in all of this is because these
;;; SPECs name global definitions.
;;;
;;; Note that this implementation is set up so that an implementation which
;;; has a 'real' function spec mechanism can use that instead and in that way
;;; get rid of setf generic function names.
;;;
(defmacro parse-gspec (spec
(non-setf-var . non-setf-case)
(setf-var . setf-case))
(declare (indentation 1 1))
(once-only (spec)
`(cond (#-setf (symbolp ,spec) #+setf t
(let ((,non-setf-var ,spec)) ,@non-setf-case))
((and (listp ,spec)
(eq (car ,spec) 'setf)
(symbolp (cadr ,spec)))
(let ((,setf-var (cadr ,spec))) ,@setf-case))
(t
(error
"Can't understand ~S as a generic function specifier.~%~
It must be either a symbol which can name a function or~%~
a list like ~S, where the car is the symbol ~S and the cadr~%~
is a symbol which can name a generic function."
,spec '(setf <foo>) 'setf)))))
;;;
;;; If symbol names a function which is traced or advised, return the
;;; unadvised, traced etc. definition. This lets me get at the generic
;;; function object even when it is traced.
;;;
(defun unencapsulated-fdefinition (symbol)
#+Lispm (si:fdefinition (si:unencapsulate-function-spec symbol))
#+Lucid (lucid::get-unadvised-procedure (symbol-function symbol))
#+excl (or (excl::encapsulated-basic-definition symbol)
(symbol-function symbol))
#+xerox (il:virginfn symbol)
#+CLISP (or (get symbol 'sys::traced-definition) (symbol-function symbol))
#+setf (fdefinition symbol)
#-(or Lispm Lucid excl Xerox CLISP setf) (symbol-function symbol))
;;;
;;; If symbol names a function which is traced or advised, redefine
;;; the `real' definition without affecting the advise.
;;;
(defun fdefine-carefully (symbol new-definition)
#+Lispm (si:fdefine symbol new-definition t t)
#+Lucid (let ((lucid::*redefinition-action* nil))
(setf (symbol-function symbol) new-definition))
#+excl (setf (symbol-function symbol) new-definition)
#+xerox (let ((advisedp (member symbol il:advisedfns :test #'eq))
(brokenp (member symbol il:brokenfns :test #'eq)))
;; In XeroxLisp (late of envos) tracing is implemented
;; as a special case of "breaking". Advising, however,
;; is treated specially.
(xcl:unadvise-function symbol :no-error t)
(xcl:unbreak-function symbol :no-error t)
(setf (symbol-function symbol) new-definition)
(when brokenp (xcl:rebreak-function symbol))
(when advisedp (xcl:readvise-function symbol)))
#+CLISP (let ((traced (get symbol 'sys::traced-definition)))
(if traced
(if (consp traced)
(progn
(sys::untrace2 symbol)
(setf (symbol-function symbol) new-definition))
(setf (get symbol 'sys::traced-definition) new-definition))
(setf (symbol-function symbol) new-definition)))
#+setf (setf (fdefinition symbol) new-definition)
#-(or Lispm Lucid excl Xerox CLISP setf)
(setf (symbol-function symbol) new-definition)
new-definition)
(defun gboundp (spec)
(parse-gspec spec
(name (fboundp name))
(name (fboundp (get-setf-function-name name)))))
(defun gmakunbound (spec)
(parse-gspec spec
(name (fmakunbound name))
(name (fmakunbound (get-setf-function-name name)))))
(defun gdefinition (spec)
(parse-gspec spec
(name (or #-setf (macro-function name) ;??
(unencapsulated-fdefinition name)))
(name (unencapsulated-fdefinition (get-setf-function-name name)))))
(defun #-setf SETF\ PCL\ GDEFINITION #+setf (setf gdefinition) (new-value spec)
(parse-gspec spec
(name (fdefine-carefully name new-value))
(name (fdefine-carefully (get-setf-function-name name) new-value))))
(proclaim '(special *the-class-t*
*the-class-vector* *the-class-symbol*
*the-class-string* *the-class-sequence*
*the-class-rational* *the-class-ratio*
*the-class-number* *the-class-null* *the-class-list*
*the-class-integer* *the-class-float* *the-class-cons*
*the-class-complex* *the-class-character*
*the-class-bit-vector* *the-class-array*
*the-class-slot-object*
*the-class-standard-object*
*the-class-structure-object*
*the-class-class*
*the-class-method*
*the-class-generic-function*
*the-class-built-in-class*
*the-class-slot-class*
*the-class-structure-class*
*the-class-standard-class*
*the-class-funcallable-standard-class*
*the-class-standard-method*
*the-class-standard-generic-function*
*the-class-standard-direct-slot-definition*
*the-class-standard-effective-slot-definition*))
(proclaim '(special *the-wrapper-of-t*
*the-wrapper-of-vector* *the-wrapper-of-symbol*
*the-wrapper-of-string* *the-wrapper-of-sequence*
*the-wrapper-of-rational* *the-wrapper-of-ratio*
*the-wrapper-of-number* *the-wrapper-of-null*
*the-wrapper-of-list* *the-wrapper-of-integer*
*the-wrapper-of-float* *the-wrapper-of-cons*
*the-wrapper-of-complex* *the-wrapper-of-c